package com.fanyue.modules.wzb.controller.admin;

import cn.hutool.json.JSONObject;
import com.fanyue.core.annotation.CoolRestController;
import com.fanyue.core.base.BaseController;
import com.fanyue.core.request.R;
import com.fanyue.modules.wzb.entity.ClothingInfoEntity;
import com.fanyue.modules.wzb.entity.ClothingSpecEntity;
import com.fanyue.modules.wzb.service.ClothingSpecService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 货位信息
 */
@Tag(name = "货位信息", description = "货位信息")
@CoolRestController(api = { "add", "delete", "update", "page", "list", "info" })
public class ClothingSpecController extends BaseController<ClothingSpecService, ClothingSpecEntity> {

    @Override
    protected void init(HttpServletRequest request, JSONObject requestParams) {
    }

    @Operation(summary = "查询类型型号")
    @GetMapping("/listByCategory")
    public R listByCategory() {
        ClothingSpecEntity selectInfo = new ClothingSpecEntity();
        selectInfo.setCategory(1);
        List<ClothingSpecEntity> list1 = service.listByInfo(selectInfo);
        selectInfo.setCategory(2);
        List<ClothingSpecEntity> list2 = service.listByInfo(selectInfo);
        selectInfo.setCategory(3);
        List<ClothingSpecEntity> list3 = service.listByInfo(selectInfo);
        selectInfo.setCategory(4);
        List<ClothingSpecEntity> list4 = service.listByInfo(selectInfo);

        List<Map<String, Object>> specList1 = new ArrayList<>();
        List<Map<String, Object>> specList2 = new ArrayList<>();
        List<Map<String, Object>> specList3 = new ArrayList<>();
        List<Map<String, Object>> specList4 = new ArrayList<>();
        for (ClothingSpecEntity spec: list1) {
            Map<String, Object> map = new HashMap<>();
            map.put("value", spec.getId());
            map.put("label", spec.getName());
            specList1.add(map);
        }
        for (ClothingSpecEntity spec: list2) {
            Map<String, Object> map = new HashMap<>();
            map.put("value", spec.getId());
            map.put("label", spec.getName());
            specList2.add(map);
        }
        for (ClothingSpecEntity spec: list3) {
            Map<String, Object> map = new HashMap<>();
            map.put("value", spec.getId());
            map.put("label", spec.getName());
            specList3.add(map);
        }
        for (ClothingSpecEntity spec: list4) {
            Map<String, Object> map = new HashMap<>();
            map.put("value", spec.getId());
            map.put("label", spec.getName());
            specList4.add(map);
        }
        Map<String, Object> data = new HashMap<>();
        data.put("specList1", specList1);
        data.put("specList2", specList2);
        data.put("specList3", specList3);
        data.put("specList4", specList4);
        return R.ok().put("data", data);
    }
}